<?php
namespace Bshop\Controller;
class IndexController extends CkadminController {
    public function index(){
    	$uid = session('bxd_shop_user_id');
    	$admin =$this->admin_name($uid);
    	$this->assign('va',$admin);
    	$this->display();
    }
    public function home(){
    	$uid = session('bxd_shop_user_id');
    	$admin =$this->admin_name($uid);
    	$this->assign('va',$admin);
    	//商家信息
    	$count = M('shop_log')->where("shop_id='{$uid}'")->count();
    	$page = new \Org\Oa\page($count,10);
    	$show = $page->show();
    	$log = M('shop_log')->where("shop_id='{$uid}'")->limit($page->firstRow.",".$page->listRows)->order("id desc")->select();
    	$this->assign('log',$log);
    	$this->assign('show',$show);
    	//结算信息
    	$clear = M('clearing_list')->where("shop_id='{$uid}'")->order("id desc")->find();
    	if($clear['clearing_end_date'] == "0000-00-00"){
    		$clear['clearing_end_date'] = date("Y-m-d");
    	}
    	if($clear['clearing_start_date'] == "0000-00-00"){
    		$clear['clearing_start_date	'] = "2015-01-01";
    	}
    	$this->assign('clear',$clear);
    	$this->display();
    }
    /**
     *  $type  
     * $method 1 活动 2会员 3金额
     */
    public function count($type,$method){
    	$today = date("Y-m-d");
    	$next = date("Y-m-d",strtotime("+ 1 day",strtotime($today)));
    	$yesterday = date("Y-m-d",strtotime("- 1 day",strtotime($today)));
    	$month = date("Y-m")."-01";
    	$endmonth = date("Y-m")."-31";
    	$week =  date("Y-m-d",mktime(0, 0 , 0,date("m"),date("d")-date("w"),date("Y")));
    	$endweek = date("Y-m-d",mktime(23,59,59,date("m"),date("d")-date("w")+6,date("Y")))." 23:59:59";
    	switch ($type){
    		//今日
    		case 1:
    			$data['add_time'] = array('between',array($today,$next));
    		break;
    		//昨日
    		case 2:
    			$data['add_time'] = array('between',array($yesterday,$today));
    		break;
    		//本周
    		case 3:
    			$data['add_time'] = array('between',array($week,$endweek));
    		break;
    		//本月
    		case 4:
    			$data['add_time'] = array('between',array($month,$endmonth));
    		break;
    		default:
    			break;
    	}
    	$data['sid'] = session('bxd_shop_user_id');
    	switch ($method){
    		case 1:
    			$count = M('goods')->where($data)->count();
    		break;
    		case 2:
    			$data['order_status'] = 1;
    			$count = M('order')->where($data)->count();
    		break;
    		case 3:
    			$data['order_status'] = 1;
    			$count = M('order')->where($data)->sum('order_amount');
    			if(empty($count)){
    				$count = "0.00";
    			}
    		break;
    	}
    	return $count;
    }
}